zUI.ActionBar = zUI.ActionBar or {}
zUI.ActionBar.lastUpdateTime = GetTime() + 1.0

zUI.ActionBar.isInited = false
zUI.ActionBar.APIHooked = false
zUI.ActionBar.EventHooked = false

zUI:RegisterComponent("zActionbars", "动作条", function ()
    -- {baseY = 60, bottomEither = 40, pet = 40, reputation = 9};
    UIPARENT_MANAGED_FRAME_POSITIONS["CastingBarFrame"] = {baseY = 70, bottomEither = 50, pet = 50, reputation = 19};

    local uiScale = 0.9
    local actionBarWidth, actionBarHeight, actionBarSpacing = 44 * uiScale, 44 * uiScale, 4 * uiScale
    local shapeShiftBarWidth, shapeShiftBarHeight, shapeShiftBarSpacing = 36 * uiScale, 36 * uiScale, 10 * uiScale
    local petActionBarWidth, petActionBarHeight, petActionBarSpacing = 36 * uiScale, 36 * uiScale, 2 * uiScale
    local xpBarHeight = 16 * uiScale

    local function roundTo(num)
        return math.floor(num * 100.0 + 0.5) / 100.0;
    end

    local function isHidden(frame)
        if (frame) then
            return (not frame:IsShown()) or (not frame:IsVisible())
        else
            return true
        end
    end

    local function isShown(frame)
        return (frame and frame:IsShown() and frame:IsVisible()) or false
    end

    zUI.zBars = CreateFrame("Frame", nil, UIParent);
    local xpbarWidth,setpoint,leftbar1h,rightbar1h,petbarh,petleftbarh,Reputbar,Reputbarh=542,0,-6,38,51,5,530,4
    -- BFA
    local function LoadActionBarBFA()

        local function CreateZBarsActionBarArtSmall(uiScale)
            local sMainActionBarFrame;
            if (isShown(BonusActionBarFrame)) then
                sMainActionBarFrame = BonusActionBarFrame;
            else
                sMainActionBarFrame = MainMenuBar;
            end
            ----------------------==[ zUI.zBars.ActionBarArtSmall-Frame ]==----------------------------------------------->
            zUI.zBars.ActionBarArtSmall = CreateFrame("Frame", "zActionBarArtSmall", sMainActionBarFrame)
            zUI.zBars.ActionBarArtSmall:SetFrameStrata("LOW")
            zUI.zBars.ActionBarArtSmall:SetScale(uiScale);
            zUI.zBars.ActionBarArtSmall:SetWidth(512)
            zUI.zBars.ActionBarArtSmall:SetHeight(128)
            --zUI.zBars.ActionBarArtSmall:SetPoint("BOTTOM", -237, -11)
            zUI.zBars.ActionBarArtSmall:SetPoint("BOTTOMLEFT", sMainActionBarFrame, 19, -13)
            -- Due to the texture being 1024x128 I had to split it in two too support Vanilla (max 512)
            -- Left split of the art.
            zUI.zBars.ActionBarArtSmall.left = zUI.zBars.ActionBarArtSmall:CreateTexture("zActionBarArtSmallLeft","BACKGROUND")
            zUI.zBars.ActionBarArtSmall.left:SetPoint("BOTTOMLEFT", zUI.zBars.ActionBarArtSmall, "BOTTOMLEFT", -256, 0);
            zUI.zBars.ActionBarArtSmall.left:SetWidth(512);
            zUI.zBars.ActionBarArtSmall.left:SetHeight(128);
            -- Right split of the art.
            zUI.zBars.ActionBarArtSmall.right = zUI.zBars.ActionBarArtSmall:CreateTexture("zActionBarArtSmallRight","BACKGROUND")
            zUI.zBars.ActionBarArtSmall.right:SetPoint("BOTTOMLEFT", zUI.zBars.ActionBarArtSmall, "BOTTOMLEFT", 256, 0);
            zUI.zBars.ActionBarArtSmall.right:SetWidth(512);
            zUI.zBars.ActionBarArtSmall.right:SetHeight(128);

            ----------------------==[ XPBarBackground-Frame ]==------------------------------------------------->
            zUI.zBars.xpbg = CreateFrame("Frame", nil, sMainActionBarFrame)
            zUI.zBars.xpbg:SetFrameStrata("BACKGROUND")
            zUI.zBars.xpbg:SetScale(uiScale);
            zUI.zBars.xpbg:SetWidth(542)
            zUI.zBars.xpbg:SetHeight(10)
            zUI.zBars.xpbg:SetPoint("BOTTOMLEFT", sMainActionBarFrame, 5, -12)
            -- xp backdrop
            zUI.zBars.xpbg.t = zUI.zBars.xpbg:CreateTexture(nil, "BACKGROUND")
            zUI.zBars.xpbg.t:SetTexture("Interface/ChatFrame/ChatFrameBackground")
            zUI.zBars.xpbg.t:SetAllPoints(zUI.zBars.xpbg)
            zUI.zBars.xpbg.t:SetTexture(0,0,0,0.85);

            --C.actionbars.endcap == "0" 的时候是隐藏
            local playerLevel = UnitLevel("player")
            if (C.actionbars.endcap == "1") or (playerLevel < 10) then
                if (C.actionbars.endcap == "1") then
                    zUI.zBars.ActionBarArtSmall.left:SetTexture("Interface\\Addons\\zUI\\img\\ActionBarArtSmallLeft")
                    zUI.zBars.ActionBarArtSmall.right:SetTexture("Interface\\Addons\\zUI\\img\\ActionBarArtSmallRight")
                else
                    zUI.zBars.ActionBarArtSmall.left:SetTexture("Interface\\Addons\\zUI\\img\\ActionBarArtSmallLeftNoGryph")
                    zUI.zBars.ActionBarArtSmall.right:SetTexture("Interface\\Addons\\zUI\\img\\ActionBarArtSmallRightNoGryph")
                end
                zUI.zBars.ActionBarArtSmall:Show();
                zUI.zBars.xpbg.t:Show()
                --mrbcat 20230727 把剩下的动作条背景也隐藏了
            else
                xpbarWidth,setpoint,leftbar1h,rightbar1h,petbarh,petleftbarh,Reputbar,Reputbarh=503,0,-10,32,41,0,503,0
                zUI.zBars.ActionBarArtSmall.left:Hide()
                zUI.zBars.ActionBarArtSmall.right:Hide()
                zUI.zBars.ActionBarArtSmall:Hide();
                zUI.zBars.xpbg.t:Hide()
            end
        end

        ----------------------==[ MicroMenuArt-Frame ]==---------------------------------------------------->
        local function CreateMarcoMenuArtFrame(uiScale)
            zUI.zBars.mma = CreateFrame("Frame", nil, UIParent)
            zUI.zBars.mma:SetFrameStrata("MEDIUM")
            zUI.zBars.mma:SetScale(uiScale)
            zUI.zBars.mma:SetWidth(512)
            zUI.zBars.mma:SetHeight(128)
            zUI.zBars.mma:SetPoint("BOTTOMRIGHT",0,0)
            zUI.zBars.mma.t = zUI.zBars.mma:CreateTexture(nil,"BACKGROUND")
            zUI.zBars.mma.t:SetTexture("Interface\\Addons\\zUI\\img\\MicroMenuArt8Slot")
            zUI.zBars.mma.t:SetAllPoints(zUI.zBars.mma)
            if (C.global.darkmode == "1") then
                zUI.zBars.mma.t:SetVertexColor(0.2, 0.2, 0.2)
            end

            if (C.global.microbuttons_auto_hide == "1") then
                zUI.zBars.Enter = CreateFrame("Frame", "MicroEnter", UIParent);
                MicroEnter:SetFrameStrata("MEDIUM")
                MicroEnter:SetScale(uiScale)
                MicroEnter:SetPoint("BOTTOMRIGHT", UIParent, 0, 0);
                MicroEnter:SetWidth(200);
                MicroEnter:SetHeight(70);
                --MicroEnter.tex = MicroEnter:CreateTexture(nil,"ARTWORK");
                --MicroEnter.tex:SetAllPoints(MicroEnter);
                --MicroEnter.tex:SetTexture(0,1,0,0.6);
                MicroEnter:EnableMouse(true);
                MicroEnter:SetScript("OnEnter", function()
                    --zPrint("Enter");
                    zUI.zBars.mma:SetPoint("BOTTOMRIGHT",0,0)
                    MicroLeave:Show();
                end)

                zUI.zBars.Leave = CreateFrame("Frame", "MicroLeave", UIParent);
                MicroLeave:SetFrameStrata("BACKGROUND");
                MicroLeave:SetScale(uiScale)
                MicroLeave:SetAllPoints(UIParent);
                MicroLeave:EnableMouse(true);
                MicroLeave:SetScript("OnEnter", function()
                    --zPrint("Leave");
                    zUI.zBars.mma:SetPoint("BOTTOMRIGHT",196,0)
                    this:Hide();
                end)
                MicroLeave:Hide();
                zUI.zBars.mma:SetPoint("BOTTOMRIGHT",196,0);
            end
        end

        --------------------==[ MICRO MENU MOVEMENT, POSITIONING AND SIZING ]==----------------------------------

        --添加双倍经验显示

        -----------------------==[[ ExhaustionTick_Update ]]==---------------------------------------BFA------->
        function zExhaustionTick_Update()
            local playerCurrXP = UnitXP("player");
            local playerMaxXP = UnitXPMax("player");
            local exhaustionThreshold = GetXPExhaustion();
            local exhaustionStateID;
            exhaustionStateID, _, _ = GetRestState();
            if (exhaustionStateID and exhaustionStateID >= 3) then
                ExhaustionTick:SetPoint("CENTER", "MainMenuExpBar", "RIGHT", 0, 0);
            end

            if (not exhaustionThreshold) then
                ExhaustionTick:Hide();
                ExhaustionLevelFillBar:Hide();
            else
                local exhaustionTickSet = max(((playerCurrXP + exhaustionThreshold) / playerMaxXP) * MainMenuExpBar:GetWidth(), 0);
                --local exhaustionTotalXP = playerCurrXP + (exhaustionMaxXP - exhaustionCurrXP);
                --local exhaustionTickSet = (exhaustionTotalXP / playerMaxXP) * MainMenuExpBar:GetWidth();
                ExhaustionTick:ClearAllPoints();
                if (exhaustionTickSet > MainMenuExpBar:GetWidth() or MainMenuBarMaxLevelBar:IsShown()) then
                    ExhaustionTick:Hide();
                    ExhaustionLevelFillBar:Hide();
                    -- Saving this code in case we want to always leave the exhaustion tick onscreen
                    --ExhaustionTick:SetPoint("CENTER", "MainMenuExpBar", "RIGHT", 0, 0);
                    --ExhaustionLevelFillBar:SetPoint("TOPRIGHT", "MainMenuExpBar", "TOPRIGHT", 0, 0);
                else
                    ExhaustionTick:Show();
                    ExhaustionTick:SetPoint("CENTER", "MainMenuExpBar", "LEFT", exhaustionTickSet, 0);
                    ExhaustionLevelFillBar:Show();
                    ExhaustionLevelFillBar:SetPoint("TOPRIGHT", "MainMenuExpBar", "TOPLEFT", exhaustionTickSet, 0);
                end
            end
            -- Hide exhaustion tick if player is max level and the reputation watch bar is shown
            if UnitLevel("player") == MAX_PLAYER_LEVEL then
                ExhaustionTick:Hide();
            end

            local exhaustionStateID = GetRestState();
            if (exhaustionStateID == 1) then
                MainMenuExpBar:SetStatusBarColor(0.0, 0.39, 0.88, 1.0);
                ExhaustionLevelFillBar:SetVertexColor(0.0, 0.39, 0.88, 0.15);
                ExhaustionTickHighlight:SetVertexColor(0.0, 0.39, 0.88);
            elseif (exhaustionStateID == 2) then
                MainMenuExpBar:SetStatusBarColor(0.58, 0.0, 0.55, 1.0);
                ExhaustionLevelFillBar:SetVertexColor(0.58, 0.0, 0.55, 0.15);
                ExhaustionTickHighlight:SetVertexColor(0.58, 0.0, 0.55);
            end

            if (ReputationWatchBar:IsShown() and not MainMenuExpBar:IsShown()) then
                ExhaustionTick:Hide();
            end
        end

        --------------------==[ DELETE AND DISABLE FRAMES ]==-----------------------------------
        local function null()
            -- I do nothing (for a reason)
        end

        --efficiant way to remove frames (does not work on textures)
        local function KillFrame(frame)
            if type(frame) == 'table' and frame.SetScript then
                frame:UnregisterAllEvents()
                frame:SetScript('OnEvent',nil)
                frame:SetScript('OnUpdate',nil)
                frame:SetScript('OnHide',nil)
                frame:Hide()
                frame.SetScript = null
                frame.RegisterEvent = null
                frame.RegisterAllEvents = null
                frame.Show = null
            end
        end

        --如果隐藏狮鹫为真
        if C.actionbars.endcap == "0" and C.actionbars.hide_xpbar == "1" then
            --如果隐藏经验条为真
            KillFrame(MainMenuExpBar)
        end
        KillFrame(MainMenuBarMaxLevelBar) --Fixed visual bug when unequipping artifact weapon at max level
        if C.actionbars.hide_shift == "1" then
            KillFrame(ShapeshiftBarFrame)
        end
        --隐藏声望栏(不可恢复，会导致很多界面问题)
        KillFrame(ReputationWatchStatusBar)
        --------------------==[ XP BAR ]==------------------------------------------------------------------>
        --隐藏经验条材质
        for i = 0, 3 do --for loop, hides MainMenuXPBarDiv (0-3)
           _G["MainMenuXPBarTexture" .. i]:Hide()
        end
        -- --------------------==[ ReputationWatchStatusBar BAR ]==------------------------------------------------------------------>
        -- for i = 0, 3 do --for loop, hides MainMenuXPBarDiv (0-3)
        --  _G["ReputationWatchBarTexture" .. i]:Hide()
        -- end
        MainMenuExpBar:SetFrameStrata("LOW")
        ExhaustionTick:SetFrameStrata("HIGH")

        MainMenuBarExpText:ClearAllPoints()
        MainMenuBarExpText:SetPoint("CENTER",MainMenuExpBar,0,1)
        MainMenuBarOverlayFrame:SetFrameStrata("MEDIUM") --changes xp bar text strata

        --------------------==[ ACTIONBARS/BUTTONS POSITIONING AND SCALING ]==-----------------------------------
        --Only needs to be run once:

        local function Initial_ActionBarLayoutBFA()
            MainMenuBarLeftEndCap:Hide()
            MainMenuBarRightEndCap:Hide()
            ReputationWatchBar:Hide()

            --reposition bottom left actionbuttons隐藏狮鹫的时候y=-12,否则为-6
            --MultiBarBottomLeftButton1:SetPoint("BOTTOMLEFT",MultiBarBottomLeft,0,leftbar1h)
            MultiBarBottomLeftButton1:SetPoint("BOTTOMLEFT",MultiBarBottomLeft,0,0)
            MultiBarBottomRightButton1:SetPoint("BOTTOMLEFT",MultiBarBottomRight,0,0)

            --reposition bottom right actionbar 右下动作条
            --MultiBarBottomRight:SetPoint("LEFT",MultiBarBottomLeft,"RIGHT",43,-6)
            MultiBarBottomRight:SetPoint("LEFT",MultiBarBottomLeft,0,actionBarHeight + actionBarSpacing)

            --reposition right bottom
            --MultiBarLeftButton1:SetPoint("TOPRIGHT",MultiBarLeft,41,11)
            MultiBarLeftButton1:SetPoint("TOPRIGHT",MultiBarLeft,0,0)

            --reposition pet actionbuttons
            --宠物技能动作条背景位置移动到屏幕外，达到隐藏效果
            SlidingActionBarTexture0:SetPoint("TOPLEFT",PetActionBarFrame,1,-200)
            PetActionButton1:ClearAllPoints()
            --PetActionButton1:SetPoint("TOP",PetActionBarFrame,"LEFT",51,4)
            PetActionButton1:SetPoint("TOP",PetActionBarFrame,"LEFT",51,4 + 0)

            -- Named ShapeshiftBarFrame in Vanilla!!
            ShapeshiftBarLeft:SetPoint("BOTTOMLEFT",ShapeshiftBarFrame,0,-5) --stance bar texture for when Bottom Left Bar is hidden
            ShapeshiftButton1:ClearAllPoints()
        end

        local function MoveMicroButtonsToBottomRight(scale)
            local zoom = 1.0; -- 1.0 / scale + 0.002;
            CharacterMicroButton:SetScale(scale * zoom);
            SpellbookMicroButton:SetScale(scale * zoom);
            TalentMicroButton:SetScale(scale * zoom);
            QuestLogMicroButton:SetScale(scale * zoom);
            SocialsMicroButton:SetScale(scale * zoom);
            WorldMapMicroButton:SetScale(scale * zoom);
            MainMenuMicroButton:SetScale(scale * zoom);
            HelpMicroButton:SetScale(scale * zoom);

            CharacterMicroButton:ClearAllPoints();
            CharacterMicroButton:SetPoint("BOTTOMRIGHT",zUI.zBars.mma,-192.5,1.9)
            --CharacterMicroButton:SetPoint("BOTTOMRIGHT",zUI.zBars.mma,-192,1)

            MainMenuBarBackpackButton:SetScale(scale / 0.9 * 0.76 * zoom)
            MainMenuBarBackpackButton:SetPoint("BOTTOMRIGHT",zUI.zBars.mma,-7,52)

            CharacterBag0Slot:SetScale(scale / 0.9 * 0.76 * zoom);
            CharacterBag1Slot:SetScale(scale / 0.9 * 0.76 * zoom);
            CharacterBag2Slot:SetScale(scale / 0.9 * 0.76 * zoom);
            CharacterBag3Slot:SetScale(scale / 0.9 * 0.76 * zoom);

            MainMenuBarPerformanceBarFrame:SetScale(scale * zoom);
            MainMenuBarPerformanceBarFrame:ClearAllPoints();
            MainMenuBarPerformanceBarFrame:SetWidth(12);
            MainMenuBarPerformanceBarFrame:SetHeight(44);
            MainMenuBarPerformanceBarFrame:SetPoint("TOPLEFT",HelpMicroButton,"TOPLEFT",23,-15)
            MainMenuBarPerformanceBarFrame:SetFrameStrata("HIGH")

            for _, v in pairs({MainMenuBarPerformanceBarFrame:GetRegions()}) do
                v:ClearAllPoints();
                v:SetWidth(12);
                v:SetHeight(44);
                v:SetPoint("TOPLEFT",HelpMicroButton,"TOPLEFT",23,-15)
            end

            MainMenuBarPerformanceBarFrameButton:SetScale(scale * zoom);
            MainMenuBarPerformanceBarFrameButton:ClearAllPoints();
            MainMenuBarPerformanceBarFrameButton:SetWidth(14);
            MainMenuBarPerformanceBarFrameButton:SetHeight(44);
            MainMenuBarPerformanceBarFrameButton:SetPoint("TOPLEFT",HelpMicroButton,"TOPLEFT",21,-15)

            KeyRingButton:SetScale(scale * zoom);
        end

        ----------------==[ BFA Style ]==------------------------------------->
        --mrbcat2023082 修改经验条宽度
        local function ActivateShortBar()
            --zUI.zBars.ActionBarArtLarge:Hide()
            --zUI.zBars.ActionBarArtSmall:Show()

            --arrows and page number

            -- Modified by shnes77, 2023-09-20, 适应 0.9 的缩放大小
            --ActionBarUpButton:SetPoint("CENTER",MainMenuBarArtFrame,"TOPLEFT",525+1,-28)
            --ActionBarDownButton:SetPoint("CENTER",MainMenuBarArtFrame,"TOPLEFT",525+1,-46)
            --MainMenuBarPageNumber:SetPoint("CENTER",MainMenuBarArtFrame,"TOPLEFT",542+3,-36)

            --ActionBarUpButton:SetPoint("CENTER",MainMenuBarArtFrame,"TOPLEFT",521,-23)
            --ActionBarDownButton:SetPoint("CENTER",MainMenuBarArtFrame,"TOPLEFT",521,-42)
            --MainMenuBarPageNumber:SetPoint("CENTER",MainMenuBarArtFrame,27,-5)

            -- Modified by shnes77, 2023-10-05, 重新设置锚点到动态的 sMainActionBarFrame 上，这样更准确。
            local sMainActionBarFrame;
            if (isShown(BonusActionBarFrame)) then
                sMainActionBarFrame = BonusActionBarFrame;
            else
                sMainActionBarFrame = MainMenuBar;
            end
            --ActionBarUpButton:ClearAllPoints()
            ActionBarUpButton:SetPoint("LEFT", sMainActionBarFrame, "RIGHT", 0, 7)
            --ActionBarDownButton:ClearAllPoints()
            ActionBarDownButton:SetPoint("LEFT", sMainActionBarFrame, "RIGHT", 0, -11)

            if C.actionbars.hide_page_number == "0" then
                MainMenuBarPageNumber:ClearAllPoints()
                --MainMenuBarPageNumber:SetPoint("CENTER", sMainActionBarFrame, "LEFT", 271*2 + 5, 0)
                MainMenuBarPageNumber:SetPoint("CENTER", sMainActionBarFrame, "RIGHT", 37, 0)
                MainMenuBarPageNumber:Show()
            else
                MainMenuBarPageNumber:Hide()
            end

            -- exp bar sizing and positioning
            MainMenuExpBar_Update();
            MainMenuExpBar:ClearAllPoints();
            -- 当隐藏狮鹫的时候经验条宽503，否者是542
            --MainMenuExpBar:SetWidth(542); MainMenuExpBar:SetHeight(10);
            MainMenuExpBar:SetWidth(xpbarWidth); MainMenuExpBar:SetHeight(10);
            MainMenuExpBar:SetPoint("BOTTOMLEFT", MainMenuBar, 5, -11);
            -- 主动作条的位置，直接影响动作条的位置，默认底部居中，271是动作条一半的宽度值，
            --MainMenuBar:SetPoint("BOTTOM", UIParent, 271, 11);
            MainMenuBar:SetPoint("BOTTOM", UIParent, "BOTTOM", (xpbarWidth / 2) / uiScale, 11);
            if ExhaustionTick:IsShown() then
                zExhaustionTick_Update();
            end
        end

        --[[
        local function Update_ActionBarsBFA()
            if isShown(MultiBarBottomRight) and isShown(MultiBarBottomLeft) then  --如果左下和右下动作条同时激活
                zPrint("左下和右下动作条同时激活")
                --MultiBarBottomLeft:SetPoint("BOTTOMLEFT",BonusActionBarFrame,0,actionBarHeight + actionBarSpacing + leftbar1h)
                --MultiBarBottomRight:SetPoint("BOTTOMLEFT",MultiBarBottomLeft,0,actionBarHeight + actionBarSpacing)
                --ShapeshiftBarFrame:SetPoint("BOTTOMLEFT",MultiBarBottomRight,0,actionBarHeight + shapeShiftBarSpacing)
                BonusActionBarFrame:ClearAllPoints()
                MultiBarBottomLeft:ClearAllPoints()
                MultiBarBottomLeft:SetPoint("BOTTOMLEFT", BonusActionBarFrame, "TOPLEFT", 0, actionBarSpacing)
                MultiBarBottomLeftButton1:ClearAllPoints()
                MultiBarBottomLeftButton1:SetPoint("LEFT", MultiBarBottomLeft, 0, actionBarSpacing - xpBarHeight)

                MultiBarBottomRight:ClearAllPoints()
                MultiBarBottomRight:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, "TOPLEFT", 0, actionBarSpacing)
                MultiBarBottomRightButton1:ClearAllPoints()
                MultiBarBottomRightButton1:SetPoint("LEFT", MultiBarBottomRight, 0, actionBarSpacing - xpBarHeight)

                --姿态栏
                --ShapeshiftButton1:SetPoint("LEFT",ShapeshiftBarFrame,-4,32)
                --ShapeshiftButton1:SetPoint("LEFT",ShapeshiftBarFrame,2,38)

                if isShown(ShapeshiftBarFrame) then
                    ShapeshiftBarFrame:ClearAllPoints();
                    ShapeshiftBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomRight, "TOPLEFT", 16, shapeShiftBarSpacing + 50)
                    ShapeshiftButton1:ClearAllPoints()
                    ShapeshiftButton1:SetPoint("LEFT", ShapeshiftBarFrame, 0, shapeShiftBarSpacing - xpBarHeight)
                    PetActionBarFrame:ClearAllPoints()
                    PetActionBarFrame:SetPoint("BOTTOMLEFT", ShapeshiftBarFrame, "BOTTOMRIGHT", 20, 0)
                    --PetActionButton1:SetPoint("LEFT",ShapeshiftBarFrame,"RIGHT",20,0)
                else
                    PetActionBarFrame:ClearAllPoints()
                    PetActionBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomRight, "TOPLEFT", 20, shapeShiftBarSpacing)
                    --PetActionButton1:SetPoint("TOP",PetActionBarFrame,"LEFT",50,petbarh + 4)
                end
            elseif isShown(MultiBarBottomRight) and not isShown(MultiBarBottomLeft) then  --如果只有右下动作条激活
                zPrint("只有右下动作条激活")
                --MultiBarBottomLeft:SetPoint("BOTTOMLEFT",BonusActionBarFrame,0,actionBarHeight + actionBarSpacing + leftbar1h)
                --MultiBarBottomRight:SetPoint("BOTTOMLEFT",MultiBarBottomLeft,0,0)
                --ShapeshiftBarFrame:SetPoint("BOTTOMLEFT",MultiBarBottomRight,0,actionBarHeight + shapeShiftBarSpacing)
                BonusActionBarFrame:ClearAllPoints()
                MultiBarBottomLeft:ClearAllPoints()
                MultiBarBottomLeft:SetPoint("BOTTOMLEFT", BonusActionBarFrame, "TOPLEFT", 0, actionBarSpacing)
                MultiBarBottomLeftButton1:ClearAllPoints()
                MultiBarBottomLeftButton1:SetPoint("LEFT", MultiBarBottomLeft, 0, actionBarSpacing - xpBarHeight)

                MultiBarBottomRight:ClearAllPoints()
                MultiBarBottomRight:SetPoint("BOTTOMLEFT", BonusActionBarFrame, "TOPLEFT", 0, actionBarSpacing)
                MultiBarBottomRightButton1:ClearAllPoints()
                MultiBarBottomRightButton1:SetPoint("LEFT", MultiBarBottomRight, 0, 0)

                --姿态栏
                --ShapeshiftButton1:SetPoint("LEFT",ShapeshiftBarFrame,-4,35)
                --ShapeshiftButton1:SetPoint("LEFT",ShapeshiftBarFrame,2,41)

                --宠物动作条
                if isShown(ShapeshiftBarFrame) then
                    ShapeshiftBarFrame:ClearAllPoints()
                    ShapeshiftBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomRight, "TOPLEFT", 16, shapeShiftBarSpacing + 50)
                    ShapeshiftButton1:ClearAllPoints()
                    ShapeshiftButton1:SetPoint("LEFT", ShapeshiftBarFrame, 0, shapeShiftBarSpacing - xpBarHeight)
                    PetActionBarFrame:ClearAllPoints()
                    PetActionBarFrame:SetPoint("BOTTOMLEFT", ShapeshiftBarFrame, "BOTTOMRIGHT", 20, 0)
                    --PetActionButton1:SetPoint("LEFT",ShapeshiftBarFrame,"RIGHT",20,0)
                else
                    PetActionBarFrame:ClearAllPoints()
                    PetActionBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, "TOPLEFT", 20, shapeShiftBarSpacing)
                    --PetActionButton1:SetPoint("TOP",PetActionBarFrame,"LEFT",50,petbarh + petleftbarh + 6)
                end
            elseif isShown(MultiBarBottomLeft) and not isShown(MultiBarBottomRight) then  --如果只有左下动作条激活
                zPrint("只有左下动作条激活")
                --MultiBarBottomLeft:SetPoint("BOTTOMLEFT",BonusActionBarFrame,0,actionBarHeight + actionBarSpacing + leftbar1h)
                --MultiBarBottomRight:SetPoint("BOTTOMLEFT",BonusActionBarFrame,0,actionBarHeight + actionBarSpacing + leftbar1h)
                --ShapeshiftBarFrame:SetPoint("BOTTOMLEFT",MultiBarBottomLeft,0,actionBarHeight + shapeShiftBarSpacing)
                BonusActionBarFrame:ClearAllPoints()
                MultiBarBottomLeft:ClearAllPoints()
                MultiBarBottomLeft:SetPoint("BOTTOMLEFT", BonusActionBarFrame, "TOPLEFT", 0, actionBarSpacing)
                MultiBarBottomRight:ClearAllPoints()
                MultiBarBottomRight:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, 0, 0)

                MultiBarBottomLeftButton1:ClearAllPoints()
                MultiBarBottomLeftButton1:SetPoint("LEFT", MultiBarBottomLeft, 0, actionBarSpacing - xpBarHeight)
                MultiBarBottomRightButton1:ClearAllPoints()
                MultiBarBottomRightButton1:SetPoint("LEFT", MultiBarBottomRight, 0, actionBarSpacing - xpBarHeight)

                --姿态栏
                --ShapeshiftButton1:SetPoint("LEFT",ShapeshiftBarFrame,-4,-10)
                --ShapeshiftButton1:SetPoint("LEFT",ShapeshiftBarFrame,2,-4)

                --宠物动作条
                if isShown(ShapeshiftBarFrame) then
                    ShapeshiftBarFrame:ClearAllPoints()
                    ShapeshiftBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, "TOPLEFT", 16, shapeShiftBarSpacing)
                    ShapeshiftButton1:ClearAllPoints()
                    ShapeshiftButton1:SetPoint("LEFT", ShapeshiftBarFrame, 0, shapeShiftBarSpacing - xpBarHeight)
                    PetActionBarFrame:ClearAllPoints()
                    PetActionBarFrame:SetPoint("BOTTOMLEFT", ShapeshiftBarFrame, "BOTTOMRIGHT", 20, 0)
                    --PetActionButton1:SetPoint("LEFT",ShapeshiftBarFrame,"RIGHT",20,0)
                else
                    PetActionBarFrame:ClearAllPoints()
                    PetActionBarFrame:SetPoint("TOPLEFT", MultiBarBottomLeft, 20, shapeShiftBarHeight + shapeShiftBarSpacing - xpBarHeight)
                    --PetActionButton1:SetPoint("TOP",PetActionBarFrame,"LEFT",50,petleftbarh + 4)
                end
            else
                zPrint("只有左下和右下动作条都不激活")
                --MultiBarBottomLeft:SetPoint("BOTTOMLEFT",BonusActionBarFrame,0,actionBarHeight + actionBarSpacing + leftbar1h)
                --MultiBarBottomRight:SetPoint("BOTTOMLEFT",BonusActionBarFrame,0,actionBarHeight + actionBarSpacing + leftbar1h)
                --ShapeshiftBarFrame:SetPoint("BOTTOMLEFT",BonusActionBarFrame,0,actionBarHeight + shapeShiftBarSpacing + leftbar1h)
                BonusActionBarFrame:ClearAllPoints()
                MultiBarBottomLeft:ClearAllPoints()
                MultiBarBottomLeft:SetPoint("BOTTOMLEFT", BonusActionBarFrame, "TOPLEFT", 0, actionBarSpacing)
                MultiBarBottomRight:ClearAllPoints()
                MultiBarBottomRight:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, 0, 0)

                MultiBarBottomLeftButton1:ClearAllPoints()
                MultiBarBottomLeftButton1:SetPoint("LEFT", MultiBarBottomLeft, 0, actionBarSpacing - xpBarHeight)
                MultiBarBottomRightButton1:ClearAllPoints()
                MultiBarBottomRightButton1:SetPoint("LEFT", MultiBarBottomRight, 0, actionBarSpacing - xpBarHeight)

                --姿态栏
                --ShapeshiftButton1:SetPoint("LEFT", ShapeshiftBarFrame, -4, -8)
                --ShapeshiftButton1:SetPoint("LEFT", ShapeshiftBarFrame, 12, -2)

                --宠物动作条
                if isShown(ShapeshiftBarFrame) then
                    ShapeshiftBarFrame:ClearAllPoints()
                    ShapeshiftBarFrame:SetPoint("BOTTOMLEFT", BonusActionBarFrame, "TOPLEFT", 16, shapeShiftBarSpacing)
                    ShapeshiftButton1:ClearAllPoints()
                    ShapeshiftButton1:SetPoint("LEFT", ShapeshiftBarFrame, 0, shapeShiftBarSpacing - xpBarHeight)
                    PetActionBarFrame:ClearAllPoints()
                    PetActionBarFrame:SetPoint("BOTTOMLEFT", ShapeshiftBarFrame, "BOTTOMRIGHT", 20, 0)
                    --PetActionButton1:SetPoint("LEFT", ShapeshiftBarFrame, "RIGHT", 20, 0)
                else
                    --PetActionButton1:SetPoint("TOP", PetActionBarFrame, "LEFT", 50, 7 - 2)
                    PetActionBarFrame:ClearAllPoints()
                    PetActionBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, "TOPLEFT", 20, shapeShiftBarSpacing - xpBarHeight)
                end
            end
            --Right Bar:
            if MultiBarRight:IsShown() then
                --do
            else
            end
            --Right Bar 2:
            if isShown(MultiBarLeft) then
                --make MultiBarRight smaller (original size)
                MultiBarLeft:SetScale(0.9)
                MultiBarRight:SetScale(0.9)
                --MultiBarRightButton1:SetPoint("TOPRIGHT",MultiBarRight,-2,534)
                MultiBarRightButton1:ClearAllPoints()
                MultiBarRightButton1:SetPoint("TOPRIGHT",MultiBarRight,-2, 65 * (1.0 / UIParent:GetEffectiveScale()))
                MultiBarLeftButton1:ClearAllPoints()
                MultiBarLeftButton1:SetPoint("TOPLEFT",MultiBarRightButton1,-44,0)
            else
                --make MultiBarRight bigger and vertically more centered, maybe also move objective frame
                MultiBarLeft:SetScale(0.9)
                MultiBarRight:SetScale(0.9)
                MultiBarRightButton1:SetPoint("TOPRIGHT",MultiBarRight,-2, 65 * (1.0 / UIParent:GetEffectiveScale()))
                --MultiBarRightButton1:SetPoint("TOPRIGHT",MultiBarRight,-2,64)
            end

            ActivateShortBar()
            -- end
        end
        --]]
        local bar_coords = {}
        local isFirstTimeSetMainActionBar = false;
        local isFirstTimeSetSideActionBar = false;

        local function printActionBarCoords(bar)
            if bar == nil then return end
            local name = bar:GetName();
            if name ~= nil then
                zPrint("Bar name: "..name);
                zPrint("left, top: "..roundTo(bar:GetLeft())..", "..roundTo(bar:GetTop()));
            end
        end

        local function printAllActionBarCoords()
            local sMainActionBarFrame;
            if (isShown(BonusActionBarFrame)) then
                sMainActionBarFrame = BonusActionBarFrame;
            else
                sMainActionBarFrame = MainMenuBar;
            end

            printActionBarCoords(sMainActionBarFrame);
            printActionBarCoords(MultiBarBottomLeft);
            printActionBarCoords(MultiBarBottomRight);

            --printActionBarCoords(ShapeshiftBarFrame);
            --printActionBarCoords(PetActionBarFrame);
            --printActionBarCoords(MultiBarLeft);
            --printActionBarCoords(MultiBarRight);
        end

        local function checkActionBarPositionChanged(bar)
            if bar == nil then return false; end
            local changed = false;
            local name = bar:GetName();
            if name ~= nil then
                if bar_coords[name] ~= nil then
                    if (bar_coords[name].isShown ~= nil and bar_coords[name].isShown ~= bar:IsShown()) then
                        changed = true;
                    elseif (bar_coords[name].isVisible ~= nil and bar_coords[name].isVisible ~= bar:IsVisible()) then
                        changed = true;
                    elseif (bar_coords[name].left ~= nil and bar_coords[name].left ~= bar:GetLeft()) then
                        changed = true;
                    elseif (bar_coords[name].top ~= nil and bar_coords[name].top ~= bar:GetTop()) then
                        changed = true;
                    elseif (bar_coords[name].scale ~= nil and bar_coords[name].scale ~= bar:GetScale()) then
                        changed = true;
                    end
                else
                    changed = true;
                end
            end
            return changed;
        end

        local function checkAllMainActionBarPositionChanged()
            if (bar_coords.uiScale ~= nil and bar_coords.uiScale ~= UIParent:GetEffectiveScale()) then
                return true;
            end
            local changed = checkActionBarPositionChanged(sMainActionBarFrame);
            if (changed) then return changed; end
            changed = checkActionBarPositionChanged(MultiBarBottomLeft);
            if (changed) then return changed; end
            changed = checkActionBarPositionChanged(MultiBarBottomRight);
            if (changed) then return changed; end

            changed = checkActionBarPositionChanged(ShapeshiftBarFrame);
            if (changed) then return changed; end
            changed = checkActionBarPositionChanged(PetActionBarFrame);
            if (changed) then return changed; end

            changed = checkActionBarPositionChanged(MultiBarLeft);
            if (changed) then return changed; end
            changed = checkActionBarPositionChanged(MultiBarRight);
            return changed;
        end

        local function checkAllSideActionBarPositionChanged()
            local changed = checkActionBarPositionChanged(MultiBarLeft);
            if (changed) then return changed; end
            changed = checkActionBarPositionChanged(MultiBarRight);
            return changed;
        end

        local function recordActionBarPosition(bar)
            if bar == nil then return false; end
            local name = bar:GetName();
            if name ~= nil then
                if bar_coords[name] == nil then
                    bar_coords[name] = {};
                end
                bar_coords[name].isShown = bar:IsShown();
                bar_coords[name].isVisible = bar:IsVisible();
                bar_coords[name].left = bar:GetLeft();
                bar_coords[name].top = bar:GetTop();
                bar_coords[name].scale = bar:GetScale();
            end
        end

        local function recordAllMainActionBarPosition()
            local sMainActionBarFrame;
            if (isShown(BonusActionBarFrame)) then
                sMainActionBarFrame = BonusActionBarFrame;
            else
                sMainActionBarFrame = MainMenuBar;
            end

            recordActionBarPosition(sMainActionBarFrame);
            recordActionBarPosition(MultiBarBottomLeft);
            recordActionBarPosition(MultiBarBottomRight);

            recordActionBarPosition(ShapeshiftBarFrame);
            recordActionBarPosition(PetActionBarFrame);
        end

        local function recordAllSideActionBarPosition()
            recordActionBarPosition(MultiBarLeft);
            recordActionBarPosition(MultiBarRight);
        end

        function zUI_Update_ActionBarsBFA()
            local sMainActionBarFrame, nMainActionBarType;
            local offsetX, offsetY;
            if (isShown(BonusActionBarFrame)) then
                sMainActionBarFrame = BonusActionBarFrame;
                nMainActionBarType = 2;
                offsetX = 4; offsetY = 0;
            else
                sMainActionBarFrame = MainMenuBar;
                nMainActionBarType = 1;
                offsetX = 8; offsetY = -17;
            end

            --printAllActionBarCoords();

            -- Check the position of all main action bar has any changed?
            local mainbarChanged = checkAllMainActionBarPositionChanged();
            --[[
            if (mainbarChanged) then
                zPrint("-------------------------------");
                zPrint("mainbarChanged = "..(mainbarChanged and "true" or "false"));
                zPrint("-------------------------------");
            end
            --]]

            if mainbarChanged or sidebarChanged or not isFirstTimeSetMainActionBar then
                if isShown(MultiBarBottomRight) and isShown(MultiBarBottomLeft) then
                    --zPrint("左下和右下动作条同时激活: "..nMainActionBarType)
                    --MultiBarBottomLeft:ClearAllPoints()
                    MultiBarBottomLeft:SetPoint("BOTTOMLEFT", sMainActionBarFrame, "TOPLEFT", offsetX, offsetY + actionBarSpacing)
                    MultiBarBottomLeftButton1:ClearAllPoints()
                    MultiBarBottomLeftButton1:SetPoint("LEFT", MultiBarBottomLeft, 0, 0)

                    --MultiBarBottomRight:ClearAllPoints()
                    MultiBarBottomRight:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, "TOPLEFT", 0, actionBarSpacing)
                    MultiBarBottomRightButton1:ClearAllPoints()
                    MultiBarBottomRightButton1:SetPoint("LEFT", MultiBarBottomRight, 0, 0)

                    if isShown(ShapeshiftBarFrame) then
                        --姿态栏
                        ShapeshiftBarFrame:ClearAllPoints();
                        ShapeshiftBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomRight, "TOPLEFT", 26, shapeShiftBarSpacing)
                        ShapeshiftButton1:ClearAllPoints()
                        ShapeshiftButton1:SetPoint("LEFT", ShapeshiftBarFrame, 0, 0)
                        --宠物动作条
                        PetActionBarFrame:ClearAllPoints()
                        PetActionBarFrame:SetPoint("BOTTOMLEFT", ShapeshiftBarFrame, "BOTTOMRIGHT", 20, 0)
                        PetActionButton1:ClearAllPoints()
                        PetActionButton1:SetPoint("LEFT", PetActionBarFrame, 0, 0)
                    else
                        PetActionBarFrame:ClearAllPoints()
                        PetActionBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomRight, "TOPLEFT", 30, petActionBarSpacing)
                        PetActionButton1:ClearAllPoints()
                        PetActionButton1:SetPoint("LEFT", PetActionBarFrame, 0, 0)
                    end
                elseif isShown(MultiBarBottomRight) and not isShown(MultiBarBottomLeft) then
                    --zPrint("只有右下动作条激活: "..nMainActionBarType)
                    --MultiBarBottomLeft:ClearAllPoints()
                    MultiBarBottomLeft:SetPoint("BOTTOMLEFT", sMainActionBarFrame, "TOPLEFT", offsetX, offsetY + actionBarSpacing)
                    MultiBarBottomLeftButton1:ClearAllPoints()
                    MultiBarBottomLeftButton1:SetPoint("LEFT", MultiBarBottomLeft, 0, 0)

                    --MultiBarBottomRight:ClearAllPoints()
                    MultiBarBottomRight:SetPoint("BOTTOMLEFT", sMainActionBarFrame, "TOPLEFT", offsetX, offsetY + actionBarSpacing)
                    MultiBarBottomRightButton1:ClearAllPoints()
                    MultiBarBottomRightButton1:SetPoint("LEFT", MultiBarBottomRight, 0, 0)

                    if isShown(ShapeshiftBarFrame) then
                        --姿态栏
                        ShapeshiftBarFrame:ClearAllPoints()
                        ShapeshiftBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomRight, "TOPLEFT", 26, shapeShiftBarSpacing)
                        ShapeshiftButton1:ClearAllPoints()
                        ShapeshiftButton1:SetPoint("LEFT", ShapeshiftBarFrame, 0, 0)
                        --宠物动作条
                        PetActionBarFrame:ClearAllPoints()
                        PetActionBarFrame:SetPoint("BOTTOMLEFT", ShapeshiftBarFrame, "BOTTOMRIGHT", 20, 0)
                        PetActionButton1:ClearAllPoints()
                        PetActionButton1:SetPoint("LEFT", PetActionBarFrame, 0, 0)
                    else
                        PetActionBarFrame:ClearAllPoints()
                        PetActionBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomRight, "TOPLEFT", 30, petActionBarSpacing)
                        PetActionButton1:ClearAllPoints()
                        PetActionButton1:SetPoint("LEFT", PetActionBarFrame, 0, 0)
                    end
                elseif isShown(MultiBarBottomLeft) and not isShown(MultiBarBottomRight) then
                    --zPrint("只有左下动作条激活: "..nMainActionBarType)
                    --MultiBarBottomLeft:ClearAllPoints()
                    MultiBarBottomLeft:SetPoint("BOTTOMLEFT", sMainActionBarFrame, "TOPLEFT", offsetX, offsetY + actionBarSpacing)
                    MultiBarBottomRight:ClearAllPoints()
                    MultiBarBottomRight:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, 0, 0)

                    --MultiBarBottomLeftButton1:ClearAllPoints()
                    MultiBarBottomLeftButton1:SetPoint("LEFT", MultiBarBottomLeft, 0, 0)
                    MultiBarBottomRightButton1:ClearAllPoints()
                    MultiBarBottomRightButton1:SetPoint("LEFT", MultiBarBottomRight, 0, 0)

                    if isShown(ShapeshiftBarFrame) then
                        --姿态栏
                        ShapeshiftBarFrame:ClearAllPoints()
                        ShapeshiftBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, "TOPLEFT", 26, shapeShiftBarSpacing)
                        ShapeshiftButton1:ClearAllPoints()
                        ShapeshiftButton1:SetPoint("LEFT", ShapeshiftBarFrame, 0, 0)
                        --宠物动作条
                        PetActionBarFrame:ClearAllPoints()
                        PetActionBarFrame:SetPoint("BOTTOMLEFT", ShapeshiftBarFrame, "BOTTOMRIGHT", 20, 0)
                        PetActionButton1:ClearAllPoints()
                        PetActionButton1:SetPoint("LEFT", PetActionBarFrame, 0, 0)
                    else
                        PetActionBarFrame:ClearAllPoints()
                        PetActionBarFrame:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, "TOPLEFT", 30, petActionBarSpacing)
                        PetActionButton1:ClearAllPoints()
                        PetActionButton1:SetPoint("LEFT", PetActionBarFrame, 0, 0)
                    end
                else
                    --zPrint("左下和右下动作条都不激活: "..nMainActionBarType)
                    --MultiBarBottomLeft:ClearAllPoints()
                    MultiBarBottomLeft:SetPoint("BOTTOMLEFT", sMainActionBarFrame, "TOPLEFT", offsetX, offsetY + actionBarSpacing)
                    MultiBarBottomRight:ClearAllPoints()
                    MultiBarBottomRight:SetPoint("BOTTOMLEFT", MultiBarBottomLeft, 0, 0)

                    --MultiBarBottomLeftButton1:ClearAllPoints()
                    MultiBarBottomLeftButton1:SetPoint("LEFT", MultiBarBottomLeft, 0, 0)
                    MultiBarBottomRightButton1:ClearAllPoints()
                    MultiBarBottomRightButton1:SetPoint("LEFT", MultiBarBottomRight, 0, 0)

                    if isShown(ShapeshiftBarFrame) then
                        --姿态栏
                        ShapeshiftBarFrame:ClearAllPoints()
                        ShapeshiftBarFrame:SetPoint("BOTTOMLEFT", sMainActionBarFrame, "TOPLEFT", offsetX + 26, offsetY + shapeShiftBarSpacing)
                        ShapeshiftButton1:ClearAllPoints()
                        ShapeshiftButton1:SetPoint("LEFT", ShapeshiftBarFrame, 0, 0)
                        --宠物动作条
                        PetActionBarFrame:ClearAllPoints()
                        PetActionBarFrame:SetPoint("BOTTOMLEFT", ShapeshiftBarFrame, "BOTTOMRIGHT", 20, 0)
                        PetActionButton1:ClearAllPoints()
                        PetActionButton1:SetPoint("LEFT", PetActionBarFrame, 0, 0)
                    else
                        PetActionBarFrame:ClearAllPoints()
                        PetActionBarFrame:SetPoint("BOTTOMLEFT", sMainActionBarFrame, "TOPLEFT", offsetX + 30, offsetY + petActionBarSpacing)
                        PetActionButton1:ClearAllPoints()
                        PetActionButton1:SetPoint("LEFT", PetActionBarFrame, 0, 0)
                    end
                end

                ActivateShortBar()

                isFirstTimeSetMainActionBar = true;

                -- Record the current position of all main action bar.
                recordAllMainActionBarPosition();
            end

            local sidebarChanged = checkAllSideActionBarPositionChanged();
            --[[
            if (sidebarChanged) then
                zPrint("-------------------------------");
                zPrint("sidebarChanged = "..(sidebarChanged and "true" or "false"));
                zPrint("-------------------------------");
            end
            --]]

            if (sidebarChanged or mainbarChanged or not isFirstTimeSetSideActionBar) then
                local coeff = 1.0 / UIParent:GetEffectiveScale();
                -- Right Bar 2:
                if isShown(MultiBarLeft) then
                    --make MultiBarRight smaller (original size)
                    MultiBarLeft:SetScale(uiScale)
                    MultiBarRight:SetScale(uiScale)
                    --MultiBarRightButton1:SetPoint("TOPRIGHT", MultiBarRight, -2, 534)
                    MultiBarRightButton1:ClearAllPoints()
                    MultiBarRightButton1:SetPoint("TOPRIGHT", MultiBarRight, -2, 60 * coeff * coeff)
                    MultiBarLeftButton1:ClearAllPoints()
                    MultiBarLeftButton1:SetPoint("TOPLEFT", MultiBarRightButton1, -44, 0)
                else
                    --make MultiBarRight bigger and vertically more centered, maybe also move objective frame
                    MultiBarLeft:SetScale(uiScale)
                    MultiBarRight:SetScale(uiScale)
                    MultiBarRightButton1:SetPoint("TOPRIGHT", MultiBarRight, -2, 60 * coeff * coeff)
                    --MultiBarRightButton1:SetPoint("TOPRIGHT", MultiBarRight, -2, 64)
                end

                isFirstTimeSetSideActionBar = true;

                -- Record the current position of all side action bar.
                recordAllSideActionBarPosition();
            end

            --printAllActionBarCoords();
        end

        function zUI_SetMainActionBarScale(uiScale)
            MainMenuBarArtFrame:SetScale(uiScale);
            MainMenuBarOverlayFrame:SetScale(uiScale);
            --MainMenuBar:SetScale(uiScale);
            BonusActionBarFrame:SetScale(uiScale);
            MultiBarBottomLeft:SetScale(uiScale);
            MultiBarBottomRight:SetScale(uiScale);
            ShapeshiftBarFrame:SetScale(uiScale);
            PetActionBarFrame:SetScale(uiScale);
            MainMenuExpBar:SetScale(uiScale);
            ExhaustionTick:SetScale(uiScale);
            ReputationWatchStatusBar:SetScale(uiScale);
            --ActionBarUpButton:SetScale(uiScale);
            --ActionBarDownButton:SetScale(uiScale);

            ActivateShortBar();
        end

        function zUI_ActionButton_OnUpdate()
            if GetTime() > zUI.ActionBar.lastUpdateTime then
                zUI_Update_ActionBarsBFA();
                zUI.ActionBar.lastUpdateTime = GetTime() + 1.0;
            end
        end

        function zUI_ActionButton_UpdateUsable()
            --zPrint("zUI_ActionButton_UpdateUsable")
        end

        function zUI_ActionButton_Update()
            --zPrint("zUI_ActionButton_Update")
        end

        function zUI_ACTIONBAR_SLOT_CHANGED(slot, reason)
            --zPrint("zUI_ACTIONBAR_SLOT_CHANGED: slot = "..slot)
        end

        function zUI_HookActionButtonEvents()
            if (zUI.ActionBar ~= nil) and not zUI.ActionBar.APIHooked then
                zUI.api.hooksecurefunc("zUI", "ActionButton_OnUpdate", zUI_ActionButton_OnUpdate)
                --zUI.api.hooksecurefunc("zUI", "ActionButton_UpdateUsable", zUI_ActionButton_UpdateUsable)
                --zUI.api.hooksecurefunc("zUI", "ActionButton_Update", zUI_ActionButton_Update)
                zUI.ActionBar.APIHooked = true
            end
        end

        function zUI_HookActionBarDisplayEvents()
            --UIParent_ManageFramePositions(); -- better to hook??
            if (zUI.ActionBar ~= nil) and not zUI.ActionBar.EventHooked then
                zUI.api.HookScript(MultiBarBottomLeft,  'OnShow', zUI_Update_ActionBarsBFA)
                zUI.api.HookScript(MultiBarBottomLeft,  'OnHide', zUI_Update_ActionBarsBFA)
                zUI.api.HookScript(MultiBarBottomRight, 'OnShow', zUI_Update_ActionBarsBFA)
                zUI.api.HookScript(MultiBarBottomRight, 'OnHide', zUI_Update_ActionBarsBFA)
                zUI.api.HookScript(MultiBarRight, 'OnShow', zUI_Update_ActionBarsBFA)
                zUI.api.HookScript(MultiBarRight, 'OnHide', zUI_Update_ActionBarsBFA)
                zUI.api.HookScript(MultiBarLeft,  'OnShow', zUI_Update_ActionBarsBFA)
                zUI.api.HookScript(MultiBarLeft,  'OnHide', zUI_Update_ActionBarsBFA)

                zUI.api.HookScript(ShapeshiftBarFrame, 'OnShow', zUI_Update_ActionBarsBFA)
                zUI.api.HookScript(ShapeshiftBarFrame, 'OnHide', zUI_Update_ActionBarsBFA)
                zUI.api.HookScript(PetActionBarFrame,  'OnShow', zUI_Update_ActionBarsBFA)
                zUI.api.HookScript(PetActionBarFrame,  'OnHide', zUI_Update_ActionBarsBFA)

                zUI.ActionBar.EventHooked = true
            end
        end

        local f = CreateFrame("Frame")
        --f:RegisterEvent("PLAYER_LOGIN") --Required to check bar visibility on load
        f:RegisterEvent("PLAYER_ENTERING_WORLD")
        --f:RegisterEvent("VARIABLES_LOADED")
        --f:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
        --f:RegisterEvent("CHAT_MSG_CHANNEL")
        --f:RegisterEvent("PLAYER_STARTED_MOVING")
        --f:RegisterEvent("PLAYER_STOPPED_MOVING")
        f:SetScript("OnUpdate", zUI_ActionButton_OnUpdate)

        f:SetScript("OnEvent", function()
            if event == "PLAYER_ENTERING_WORLD" then
                if (zUI.ActionBar ~= nil) and not zUI.ActionBar.isInited then
                    MoveMicroButtonsToBottomRight(uiScale);
                    CreateZBarsActionBarArtSmall(uiScale);
                    CreateMarcoMenuArtFrame(uiScale);
                    Initial_ActionBarLayoutBFA();
                    zUI_SetMainActionBarScale(uiScale);
                    zUI_Update_ActionBarsBFA();
                    zUI_HookActionBarDisplayEvents();
                    --zUI_HookActionButtonEvents();

                    zUI.ActionBar.isInited = true;
                    --f:UnregisterEvent("PLAYER_LOGIN"); --only run once, well feels good man to be safe. MODIFIED
                    f:UnregisterEvent("PLAYER_ENTERING_WORLD");
                end
            end
        end)
    end

    --------------------==[ BLIZZARD TEXTURES ]==----------------------------------
    if false then
        --隐藏主动作条背景
        for i = 0, 3 do --for loop, hides MainMenuBarTexture (0-3)
            if _G["MainMenuBarTexture" .. i] then
               _G["MainMenuBarTexture" .. i]:Hide()
            end
        end
        for i = 0, 1 do --for loop, hides BonusActionBarTexture (0-1)
            if _G["BonusActionBarTexture" .. i] then
               _G["BonusActionBarTexture" .. i]:Hide()
            end
        end
    end
    --ReputationXPBarTexture0
    --隐藏声望条材质
    for i = 0, 3 do --for loop, hides MainMenuBarTexture (0-3)
        _G["ReputationXPBarTexture" .. i]:Hide()
    end
    --隐藏姿态栏背景材质
    local actionbarpaging = {
       -- actionbar paging
        MainMenuBarPageNumber, ActionBarUpButton, ActionBarDownButton,
    }

    local playerLevel = UnitLevel("player")
    if playerLevel == MAX_PLAYER_LEVEL then
        ReputationWatchBar:ClearAllPoints()
        ReputationWatchBar:SetPoint("BOTTOMLEFT", MainMenuBar, 5, Reputbarh)
    end

    local frames = {
        -- xp and reputation bar
        MainMenuXPBarTexture2, MainMenuXPBarTexture3,
        ReputationWatchBarTexture2, ReputationWatchBarTexture3,
        -- actionbar backgrounds
        MainMenuBarTexture0, MainMenuBarTexture1, MainMenuBarTexture2, MainMenuBarTexture3,
        BonusActionBarFrameTexture0, BonusActionBarFrameTexture1,
        --MainMenuBarArtFrameTexture2, MainMenuBarArtFrameTexture3,
        MainMenuMaxLevelBar2, MainMenuMaxLevelBar3,
        ShapeshiftBarLeft, ShapeshiftBarMiddle, ShapeshiftBarRight,
    }
    local normtextures = {
        ShapeshiftButton1, ShapeshiftButton2,
        ShapeshiftButton3, ShapeshiftButton4,
        ShapeshiftButton5, ShapeshiftButton6,
    }
    --隐藏一些背景材质
    -- clear textures
    for id, frame in pairs(frames) do
        zUI.api.hide(frame)
    end

    --显示隐藏动作条翻页
    if C.actionbars.hide_paging == "1" then
        for id, frame in pairs(actionbarpaging) do
            zUI.api.hide(frame)
        end
    end

    --隐藏姿态栏背景材质
    for id, frame in pairs(normtextures) do
        zUI.api.hide(frame, 2)
    end

    LoadActionBarBFA();
end)
